package com.online_vote_system.demo.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.sql.SQLException;


@Configuration
public class MyDatasourceConfig {
    //默认的自动配置是判断容器中没有才会配
    @ConfigurationProperties("spring.datasource")//将组件跟配置文件进行绑定
    @Bean
    /**
     *设置数据源
     **/
    public DataSource dataSource() throws SQLException {
        DruidDataSource druidDataSource = new DruidDataSource();

//        druidDataSource.setUrl();
//        druidDataSource.setUsername();
//        druidDataSource.setPassword();//直接用上面 @ConfigurationProperties("spring.datasource")替代
        //加入监控功能和防火墙功能
        druidDataSource.setFilters("stat,wall");
        return druidDataSource;
    }
}
